package maiyatian.videolive.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import maiyatian.videolive.common.ConstentInfo;
import maiyatian.videolive.IActivity;
import maiyatian.videolive.IFragment;
import maiyatian.videolive.MainActivity;
import maiyatian.videolive.R;
import maiyatian.videolive.leftPersonCenter.PersonCenterActivity;
import maiyatian.videolive.activity.PersonHomeActivity;
import maiyatian.videolive.activity.WebviewActivity;
import maiyatian.videolive.leftPersonCenter.fragment.EditInfoFragment;
import maiyatian.videolive.leftPersonCenter.fragment.MyAccountFragment;
import maiyatian.videolive.leftPersonCenter.fragment.MyProfitFragment;
import maiyatian.videolive.leftPersonCenter.fragment.SettingListFragment;
import maiyatian.videolive.fragment.personHome.LiveInfoFragment;
import maiyatian.videolive.login.LoginHomeActivity;

/**
 * Created by 王中阳 on 2016/5/9.
 */
@ContentView(R.layout.fragment_leftperson)
public class PersonLeftFragment extends IFragment implements View.OnClickListener {
    public static final String TAG = "PersonLeftFragment";
    private MainActivity mycontext;

    @ViewInject(R.id.boxSetting)
    LinearLayout boxSetting;
    @ViewInject(R.id.boxAccount)
    LinearLayout boxAccount;
    @ViewInject(R.id.boxProfit)
    LinearLayout boxProfit;
    @ViewInject(R.id.boxLiving)
    LinearLayout boxLiving;
    @ViewInject(R.id.boxLevel)
    LinearLayout boxLevel;
    @ViewInject(R.id.boxAuth)
    LinearLayout boxAuth;
    @ViewInject(R.id.avator)
    ImageView avator;
    @ViewInject(R.id.ivEdit)
    ImageView ivEdit;
    @ViewInject(R.id.logout)
    TextView logout;

    public PersonLeftFragment() {

    }

    public static PersonLeftFragment newInstance() {
        PersonLeftFragment fragment = new PersonLeftFragment();
        return fragment;
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        mycontext = (MainActivity) context;
    }


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return x.view().inject(this, inflater, container);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        boxSetting.setOnClickListener(this);
        boxAccount.setOnClickListener(this);
        boxAuth.setOnClickListener(this);
        boxLevel.setOnClickListener(this);
        boxLiving.setOnClickListener(this);
        boxProfit.setOnClickListener(this);
        avator.setOnClickListener(this);
        ivEdit.setOnClickListener(this);
        logout.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent();
        switch (v.getId()) {
            case R.id.boxAccount:
                intent.setClass(getActivity(), PersonCenterActivity.class);
                intent.putExtra(IActivity.PAGETO, MyAccountFragment.TAG);
                break;
            case R.id.boxSetting:
                intent.setClass(getActivity(), PersonCenterActivity.class);
                intent.putExtra(IActivity.PAGETO, SettingListFragment.TAG);
                break;
            case R.id.boxAuth:
                intent.setClass(getActivity(), WebviewActivity.class);
                intent.putExtra(IActivity.PAGETO, ConstentInfo.USER_AUTH);
                break;
            case R.id.boxLevel:
                intent.setClass(getActivity(), WebviewActivity.class);
                intent.putExtra(IActivity.PAGETO, ConstentInfo.USER_LEVEL);
                break;
            case R.id.boxLiving:
                intent.setClass(getActivity(), PersonCenterActivity.class);
//                intent.putExtra(IActivity.PAGETO, MyLiveFragment.TAG); // TODO: 2016/5/11  测试数据
                intent.putExtra(IActivity.PAGETO, LiveInfoFragment.TAG);
                break;
            case R.id.boxProfit:
                intent.setClass(getActivity(), PersonCenterActivity.class);
                intent.putExtra(IActivity.PAGETO, MyProfitFragment.TAG);
                break;
            case R.id.ivEdit:
                intent.setClass(getActivity(), PersonCenterActivity.class);
                intent.putExtra(IActivity.PAGETO, EditInfoFragment.TAG);
                break;
            case R.id.avator:
                intent.setClass(getContext(), PersonHomeActivity.class);
            case R.id.logout:
                intent.setClass(getContext(), LoginHomeActivity.class);
        }
        mycontext.startActivity(intent);
        mycontext.closeLeftFragment(); //关闭侧滑栏
    }
}
